package netapp.inetaddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class Test1 {
    public static void main(String[] args) throws UnknownHostException {
        InetAddress nanako = InetAddress.getByName("nanako");
        System.out.println(nanako);
        // 获取此ip的主机名
        System.out.println("hostname = " + nanako.getHostName());
        System.out.println("nanako.getHostAddress() = " + nanako.getHostAddress());

        // 测试特殊地址
        System.out.println("-------------------------");
        InetAddress ip = InetAddress.getByName("localhost");
        System.out.println("ip = " + ip);
        System.out.println("ip.getHostName() = " + ip.getHostName());
        System.out.println("ip.getHostAddress() = " + ip.getHostAddress());
    }
}
